﻿/* 
 * 
 * Copyright 2013 Bendsoft. All rights reserved.
 * http://www.bendsoft.com
 * 
 * This code is distributed under the New BSD License (BSD).
 * 
 * @package     Camelot SharePoint Integration Library
 * @codeplex    http://camelottoolkit.codeplex.com
 * @license     New BSD License (BSD)
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Camelot.SharePointIntegration.Client
{
    public class ListData : IDisposable
    {
        protected internal DataSet Content { get; set; }

        public ListDescription Description { get; protected internal set; }

        public DataTable Schema
        {
            get
            {
                if (Content != null && Content.Tables.Contains("Schema"))
                    return Content.Tables["Schema"];
                else
                    return null;
            }
        }

        public DataTable Attachments
        {
            get
            {
                if (Content != null && Content.Tables.Contains("Attachments"))
                    return Content.Tables["Attachments"];
                else
                    return null;
            }
        }

        public DataTable Rows
        {
            get
            {
                if (Content != null && Content.Tables.Contains("Rows"))
                    return Content.Tables["Rows"];
                else
                    return null;
            }
        }

        #region "IDisposable Support"

        bool disposed = false;
        private void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    // free managed resources
                    if (Content != null)
                    {
                        Content.Dispose();
                        Content = null;
                    }
                }

                Description = null;
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        ~ListData()
        {
            Dispose(false);
        }

        #endregion

    }
}